<template>
  <!--个人求助评论页面-->
  <div id="top">
    <div>
      <el-card id="search">
        <!--        <el-input v-model="titlename" placeholder="请输入标题名"></el-input>-->
        <el-input v-model="userInfo" placeholder="请输入用户名"></el-input>
        <el-button type="primary" plain @click="doQury()">查询</el-button>
      </el-card>
    </div>
    <el-table :data="currentPageData"  stripe id="ta">
      <el-table-column prop="arid" label="评论ID" width="300" class="tata"/>
      <el-table-column prop="assistanceList.atitle" label="帖子" width="300" class="tata"/>
      <el-table-column prop="assreview" label="评论内容" width="300" class="tata"/>
      <el-table-column prop="user.uname" label="评论用户" width="200" class="tata"/>
      <el-table-column prop="createdate" label="评论时间" width="450" class="tata"/>
      <el-table-column fixed="right" label="操作" width="220">

          <template #default="scope">
            <el-popconfirm title="你确定要删除此评论吗?" @confirm="del(scope.row)">
            <template #reference>
              <el-button link type="primary" size="small">删除</el-button>
            </template>
            </el-popconfirm>
          </template>
      </el-table-column>
    </el-table>

    <!--  分页组件-->
    <el-pagination
        v-model="currentPage"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="totalData.length"
        @current-change="handleCurrentChange">
    </el-pagination>
  </div>

</template>

<script>
import doThis from "@/api/getData";

export default {
  name: "AssReview",
  data() {
    return {

      assreviewlist: [],
      asstitlelist:{},
      userInfo: '',
      dialogVisible:false,
      //  分页
      tableData: [], // 总数据
      totalData: [], // 总数据
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页显示的条数
    }
  },
  computed: {
    // 根据当前页面和每页显示的条数，计算分页后的数据
    currentPageData() {
      const {totalData, currentPage, pageSize} = this;
      const start = (currentPage - 1) * pageSize;
      const end = start + pageSize;
      return totalData.slice(start, end);
    },
  },
  mounted() {
    this.getAssReviewList()
  },
  methods: {
    // 切换页码时的回调函数
    handleCurrentChange(page) {
      this.currentPage = page;
    },
    getAssReviewList() {
      doThis.doGet("/assreview/list", null).then(res => {
        console.log("全部评论----", res.data)
        // this.assreviewlist=res.data
        this.tableData = res.data
        this.totalData = res.data
      })
    },
    doQury() {
      doThis.doGet("/assreview/list", {uname: this.userInfo}).then(res => {
        console.log("搜索成功", res.data)
        this.tableData = res.data
        this.totalData = res.data
      })
    },
    del(row) {
      doThis.doGet("/assreview/delete", {arid: row.arid}).then(res => {
        console.log("删除成功-------", res.data)
        this.getAssReviewList()
      })
    },
  }
}
</script>

<style scoped>
.tata {
  width: 400px;
}

#top {
  margin-top: 47px;
  margin-left: -30px;
  background-color: #EBEBEB;
}

#search .el-input {
  width: 200px;
  margin-left: 30px;
  margin-right: 30px;
}

#search .el-button {
  margin-left: 30px;
  margin-right: 30px;
}
</style>